package com.tjh.spring5.testdemo;

import org.junit.Test;
import org.springframework.context.support.GenericApplicationContext;

/**
 * day37：
 *      函数式注册对象
 * Create by koala on 2022-11-12
 */
public class GenericApplicationContextTest {

    // day37：函数式风格创建对象，交给spring进行管理
    @Test
    public void testGenericApplicationContext() {
        //1 创建GenericApplicationContext对象
        GenericApplicationContext context = new GenericApplicationContext();
        //2 调用context的方法对象注册
        context.refresh();
        //context.registerBean(User.class,() -> new User()); // 此处搭配底下的user0
        context.registerBean("user1",User.class,() -> new User());// 此处搭配底下的user1
        //3 获取在spring注册的对象
        /*User user0 = (User)context.getBean("com.tjh.spring5.testdemo.User");
        System.out.println(user0);*/
        User user1 = (User)context.getBean("user1");
        System.out.println(user1);
    }

}